import 'package:http/http.dart' as http;
import 'package:dio/dio.dart';

void main() {
  //print(getMessageByHttp());

  getMessageByDio();
}

// HttpClient Dart原生http请求
getMessageByHttpClient() {}

// http库(官方提供)
Future<String> getMessageByHttp() async {
  try {
    final response = await http.get(Uri.parse("https://www.baidu.com/"));
    if (response.statusCode == 200) {
      var body = response.body;
      print(body);
      return response.body;
    }
  } catch (e) {
    print(e);
  }
  return null;
}

// dio三方库
getMessageByDio() {
  // 创建Dio
  final dio = Dio();
  // get请求
  dio.get("http://httpbin.org/get").then((value) => print(value));
  // post请求
  dio.post("http://httpbin.org/post").then((value) => print(value));
}
